package com.CST.controller.ys;

import com.CST.common.api.ResultObject;
import com.CST.dto.ys.YsSubjectDTO;
import com.CST.entity.ys.YsSubject;
import com.CST.service.ys.YsSubjectService;
import com.CST.vo.ys.DeptVO;
import com.CST.vo.ys.YsSubjectListVO;
import com.CST.vo.ys.YsSubjectVO;
import com.CST.vo.ys.YySubjectVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author qtx
 * @since 2023-04-23
 */
@Api(tags = "预算科目管理")
@RestController
@RequestMapping("/ysSubject")
public class YsSubjectController {

    private final YsSubjectService service;

    public YsSubjectController(YsSubjectService service) {
        this.service = service;
    }

    @ApiOperation("分页查询")
    @PostMapping("/listYsSubjectPage")
    public ResultObject<IPage<YsSubjectVO>> listYsSubjectPage(@RequestBody YsSubjectDTO dto) {
        return ResultObject.success(service.listYsSubjectPage(dto));
    }

    @ApiOperation("层级查询")
    @PostMapping("/listYsSubject")
    public ResultObject<List<YsSubjectVO>> listYsSubjectTree() {
        return ResultObject.success(service.listYsSubjectTree());
    }

    @ApiOperation("末级节点查询")
    @PostMapping("/listYsSubjectChild")
    public ResultObject<List<YsSubjectListVO>> listYsSubject() {
        return ResultObject.success(service.listYsSubject());
    }

    @ApiOperation("业务量配套下拉数据")
    @GetMapping("/listYsSubject1")
    public ResultObject<List<YsSubjectListVO>> listYsSubject1(String name) {
        return ResultObject.success(service.listYsSubject1(name));
    }

    @ApiOperation("资产下拉数据")
    @GetMapping("/listYsSubject2")
    public ResultObject<List<YsSubjectListVO>> listYsSubject2(String name) {
        return ResultObject.success(service.listYsSubject2(name));
    }

    @ApiOperation("费用下拉数据")
    @GetMapping("/listYsSubject3")
    public ResultObject<List<YsSubjectListVO>> listYsSubject3(String name) {
        return ResultObject.success(service.listYsSubject3(name));
    }

    @ApiOperation("业务下拉数据")
    @GetMapping("/listYsSubject4")
    public ResultObject<List<YsSubjectListVO>> listYsSubject4(String name) {
        return ResultObject.success(service.listYsSubject4(name));
    }

    @ApiOperation("管理下拉数据")
    @GetMapping("/listYsSubject5")
    public ResultObject<List<YsSubjectListVO>> listYsSubject5(String name) {
        return ResultObject.success(service.listYsSubject5(name));
    }

    @ApiOperation("管理下拉数据-预算科目对应的部门数据")
    @GetMapping("/listManageDept")
    public ResultObject<List<DeptVO>> listManageDept(@RequestParam("subjectId") Long subjectId){
        List<DeptVO> deptList = service.listManageDept(subjectId);
        return ResultObject.success(deptList);
    }

    @ApiOperation("业务和管理对照用友下拉数据")
    @GetMapping("/listYySubject")
    public ResultObject<List<YySubjectVO>> listYySubject(@RequestParam String year, String name) {
        return ResultObject.success(service.listYySubject(year, name));
    }

    @ApiOperation("新增或编辑")
    @PostMapping("/saveOrUpdateYsSubject")
    public ResultObject<Boolean> saveOrUpdateYsSubject(@RequestBody YsSubject entity) {
        return ResultObject.success(service.saveOrUpdateYsSubject(entity));
    }

    @ApiOperation("编辑保存前调用判断")
    @PostMapping("/getExistingRelationship")
    public ResultObject<String> getExistingRelationship(@RequestBody YsSubject entity){
        return service.getExistingRelationship(entity);
    }

    @ApiOperation("删除预算科目")
    @DeleteMapping("/removeYsSubjectById")
    public ResultObject<Boolean> removeYsSubjectById(@RequestParam Long id) {
        return ResultObject.success(service.removeYsSubjectById(id));
    }

    @ApiOperation("导入")
    @PostMapping("/importExcelYsSubject")
    public void importExcelYsSubject(MultipartFile file) {
        service.importExcelYsSubject(file);
    }

    @ApiOperation("导出")
    @PostMapping("/exportExcelYsSubject")
    public void exportExcelYsSubject(HttpServletResponse response) {
        service.exportExcelYsSubject(response);
    }

    @ApiOperation("导出模板")
    @PostMapping("/exportExcelYsSubjectDemo")
    public void exportExcelYsSubjectDemo(HttpServletResponse response) {
        service.exportExcelYsSubjectDemo(response);
    }
}
